<template>
  <n-spin :show="appLoading">
    <div class="app-wrap">
      <router-view></router-view>
    </div>
    <SwitchEnvCpt></SwitchEnvCpt>
  </n-spin>
</template>

<script lang="ts">
import { defineComponent, toRef } from 'vue';
import { useRouter } from 'vue-router';

import { fetchGithubLogin, fetchBindGithub } from '@/api/githubUser';
import { fetchQQLogin, fetchBindQQ } from '@/api/qqUser';
import SwitchEnvCpt from '@/components/SwitchEnv/index.vue';
import { POSTMESSAGE_TYPE } from '@/constant';
import { useAppStore } from '@/store/app';
import { useUserStore } from '@/store/user';

export default defineComponent({
  components: { SwitchEnvCpt },
  setup() {
    const router = useRouter();
    const appStore = useAppStore();
    const userStore = useUserStore();

    const appLoading = toRef(appStore, 'loading');

    window.addEventListener('message', async (e) => {
      const { type, data: code } = e.data;
      // console.log('收到消息', type, code);
      if (!POSTMESSAGE_TYPE.includes(type)) return;
    });

    return { appLoading };
  },
});
</script>

<style lang="scss" scoped>
.app-wrap {
  min-height: 100vh;
}
</style>
